﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using _MetalSlug.Soldiers.Units;
using System.Xml;
using Microsoft.Xna.Framework;
using _MetalSlug.MyCharacters.Characters;
using Microsoft.Xna.Framework.Graphics;
using _MetalSlug.Mementoes;
using Microsoft.Xna.Framework.Input;

namespace _MetalSlug.Mission
{
    public class MyMission
    {
        MyCharacter hero;
        public MyCharacter Hero
        {
            get { return hero; }
            set { hero = value; }
        }

        MyMap map;
        public MyMap Map
        {
            get { return map; }
            set { map = value; }
        }

        int level;
        public int Level
        {
            get { return level; }
            set { level = value; }
        }
        List<Enemy> lstEnemy;
        public List<Enemy> LstEnemy
        {
            get { return lstEnemy; }
            set { lstEnemy = value; }
        }

        public MyMission(int newLevel)
        {
            Level = newLevel;
            LstEnemy = new List<Enemy>();
        }

        public void Update(GameTime gameTime)
        {
            GameUtil.GamePivot.Update(Map, Hero);
            Map.Update(gameTime);
            Hero.Update(gameTime, lstEnemy);
            lstEnemy.RemoveAll(item => item.IsDead && item.Type != Enemy.TYPE_SOLDIER.TYCOON);
            foreach (Enemy enemy in lstEnemy)
            {
                enemy.Update(gameTime, Map, Hero);
            }
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            Map.Draw(spriteBatch);
            foreach (Enemy enemy in lstEnemy)
            {
                enemy.Draw(spriteBatch);
            }

            Hero.Draw(spriteBatch);
        }

        public Boolean isGameOver()
        {
            return Hero.Isdead;
        }

        public List<Enemy> GetListEnemy()
        {
            return lstEnemy;
        }

        public Boolean HeroIsAlive()
        {
            return Hero.Hp > 0;
        }

        public Enemy GetTycoon()
        {
            return lstEnemy.Where(enemy=> enemy.Type == Enemy.TYPE_SOLDIER.TYCOON).SingleOrDefault();
        }

    }
}
